package org.high5.paintmyworld;

import org.high5.dataprovider.MyDBAdapter;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.database.Cursor;
import android.util.Log;

// this is the class for dealing with the users changes to the settings
public class NotifyChangePref implements  OnSharedPreferenceChangeListener{

	public final String TAG = "PaintMyWorld-NotifyChangePref";
	
	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
			String key) {
		boolean collectGPS = sharedPreferences.getBoolean("pref_collectdata", false);
		boolean on = true;
		MyDBAdapter db = new MyDBAdapter(MainActivity.getMainActivityContext());
		db.open();
		Cursor query = db.getUserPrefs();
		String seconds = null;
		if (query.moveToFirst()){
			seconds = query.getString(1);
		}
		if (collectGPS) {
			
			db.updateUserPrefs(1, seconds, "1");
		}else{
			db.updateUserPrefs(1, seconds, "0");
			
		}
		
		Log.i(TAG,"user has made a change to the preference called: "+key);
		
	}

}
